<template>
  <a-card :bordered="false">
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
      </a-table>

    <!-- table区域-end -->

    <!-- 表单区域 -->
    <sysAnnouncement-modal ref="modalForm" @ok="modalFormOk"></sysAnnouncement-modal>
    <!-- 查看详情 -->
    <j-modal class="detail-modal" title="查看详情" :visible.sync="detailModal.visible" :top="50" :width="600" switchFullscreen :footer="null">
      <iframe v-if="detailModal.url" class="detail-iframe" :src="detailModal.url"/>
    </j-modal>

  </a-card>
</template>

<script>
    import SysAnnouncementModal from './modules/SysAnnouncementModal'
    import {doReleaseData, doReovkeData} from '@/api/api'
    import {getAction} from '@/api/manage'
    import {JeecgListMixin} from '@/mixins/JeecgListMixin'
    import { ACCESS_TOKEN } from '@/store/mutation-types'

    export default {
        name: "SysAnnouncementList",
        mixins: [JeecgListMixin],
        components: {
            SysAnnouncementModal
        },
        data() {
            return {
                description: '系统通告表管理页面',
                // 查询条件
                queryParam: {},
                // 表头
                columns: [
                    {
                        title: '#',
                        dataIndex: '',
                        key: 'rowIndex',
                        width: 60,
                        align: "center",
                        customRender: function (t, r, index) {
                            return parseInt(index) + 1;
                        }
                    },
                    {
                        title: '方法名',
                        align: "center",
                        dataIndex: 'fileName'
                    },
                    {
                        title: 'api',
                        align: "center",
                        dataIndex: 'filePath'
                    },
                    {
                      title: 'URL',
                      align: "center",
                      dataIndex: 'fileUrl'
                    },
                    {
                        title: '请求方式',
                        align: "center",
                        dataIndex: 'method'
                    },
                ],
                detailModal: {visible: false, url: '',},
                url: {
                    list: "/magic/magicApiFile/queryPathAll",
                    delete: "/sys/annountCement/delete",
                    deleteBatch: "/sys/annountCement/deleteBatch",
                    releaseDataUrl: "/sys/annountCement/doReleaseData",
                    reovkeDataUrl: "sys/annountCement/doReovkeData",
                    exportXlsUrl: "sys/annountCement/exportXls",
                    importExcelUrl: "sys/annountCement/importExcel",
                },
            }
        },
        computed: {
            importExcelUrl: function(){
                return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
            }
        },
        methods: {
            //执行发布操作
            releaseData: function (id) {
                console.log(id);
                var that = this;
                doReleaseData({id: id}).then((res) => {
                    if (res.success) {
                        that.$message.success(res.message);
                        that.loadData(1);
                    } else {
                        that.$message.warning(res.message);
                    }
                });
            },
            //执行撤销操作
            reovkeData: function (id) {
                var that = this;
                doReovkeData({id: id}).then((res) => {
                    if (res.success) {
                        that.$message.success(res.message);
                        that.loadData(1);
                        this.syncHeadNotic(id)
                    } else {
                        that.$message.warning(res.message);
                    }
                });
            },
            syncHeadNotic(anntId){
                getAction("sys/annountCement/syncNotic",{anntId:anntId})
            },
            handleDetail:function(record){
                const domain = window._CONFIG['domianURL']
                const token = this.$ls.get(ACCESS_TOKEN)
                this.detailModal.url = `${domain}/sys/annountCement/show/${record.id}?token=${token}`
                this.detailModal.visible = true
            },
        }
    }
</script>
<style scoped lang="less">
  @import '~@assets/less/common.less';

  /** 查看详情弹窗的样式 */
  .detail-modal {
    .detail-iframe {
      border: 0;
      width: 100%;
      height: 88vh;
      min-height: 600px;
    }

    &.fullscreen .detail-iframe {
      height: 100%;
    }
  }

  .detail-modal /deep/ .ant-modal {
    top: 30px;

    .ant-modal-body {
      font-size: 0;
      padding: 0;
    }
  }

  .detail-modal.fullscreen /deep/ .ant-modal {
    top: 0;
  }

</style>